import request from '@/utils/request'
import type {
  ICateGory1,
  IAttrInfo,
  IAttrInfoDataList,
  IAttrInfoData,
} from './type'

enum API {
  GET_CATEGORY1_LIST = '/admin/product/getCategory1',
  GET_CATEGORY2_LIST = '/admin/product/getCategory2',
  GET_CATEGORY3_LIST = '/admin/product/getCategory3',
  GET_ATTRINFO_LIST = '/admin/product/attrInfoList/',
  ADD_ATTRINFO = '/admin/product/saveAttrInfo',
}

// 获取一级分类列表
export const getCateGory1 = () => {
  return request.get<any, ICateGory1>(API.GET_CATEGORY1_LIST)
}

export const getAttrInfoList = ({
  category1Id,
  category2Id,
  category3Id,
}: IAttrInfo) => {
  return request.get<any, IAttrInfoDataList>(
    API.GET_ATTRINFO_LIST + `${category1Id}/${category2Id}/${category3Id}`,
  )
}

export const addAttrInfo = (data: IAttrInfoData) => {
  return request.post<any, any>(API.ADD_ATTRINFO, data)
}
